#pragma once

// Copyright (c) 2010 Manuel Peinado Gallego <manuel.peinado@gmail.com>
// Distributed under the MIT license


#include "UiFollower.h"
#include "ScintillaCtrl.h"
#include "PythonManager.h"


class CEditorToolBar : public CMFCToolBar
{
public:
   virtual void OnUpdateCmdUI(CFrameWnd* /*pTarget*/, BOOL bDisableIfNoHndler)
    {
        CMFCToolBar::OnUpdateCmdUI((CFrameWnd*) GetOwner(), bDisableIfNoHndler);
    }
    virtual BOOL AllowShowOnList() const { return FALSE; }
};

/////////////////////////////////////////////////////////////////////////////
// COutputList window

class COutputList : public CListBox
{
// Construction
public:
    COutputList();

// Implementation
public:
    virtual ~COutputList();

protected:
    afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
    afx_msg void OnEditCopy();
    afx_msg void OnEditClear();
    afx_msg void OnViewOutput();

    DECLARE_MESSAGE_MAP()
};

class COutputWnd : public CDockablePane, public UiFollower
{
// Construction
public:
    
    COutputWnd();


    bool hasFocus() const; // Should actually be called "pyWndHasFocus"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

protected:
    
    CFont m_Font;

    // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    // Some helper functions to work with editor toolbars

    void createEditorToolbar(CEditorToolBar& toolBar, int resourceId);
    CSize adjustEditorToolBarLayout(const CRect& rectClient,
                                    CEditorToolBar& toolBar);
    std::string getEditorText(CScintillaCtrl& editor);
    
    // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

    CEditorToolBar m_wndPythonToolBar;
    CScintillaCtrl m_wndPython;
    std::string getPythonScript();

    void AdjustLayout() override;

    // Sets style of scintilla text control
    void setAStyle(CScintillaCtrl& rCtrl, int style, COLORREF fore, 
                   COLORREF back=RGB(0xff, 0xff, 0xff), int size=-1, 
                   const char *face=0);
    void setSyntaxColors(CScintillaCtrl& rCtrl);


    // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    
    CScintillaCtrl m_wndShader;
    CEditorToolBar m_wndShaderToolBar;
    int m_shaderTabIndex;
    std::string getShaderCode();

    // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

    CMFCTabCtrl	m_wndTabs;

    COutputList m_wndOutputLog;


    // --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  
    // UiFollower overrides

    void onMessage(LogManager* sender, const std::string& msg) override;
    void onSelectionChanged(SelectionManager* sender) override;

    // --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  

// Implementation
public:

    virtual ~COutputWnd();

protected:
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnSize(UINT nType, int cx, int cy);

    // Python toolbar command message handlers
    afx_msg void OnPythonUndo();
    afx_msg void OnPythonRedo();

    afx_msg void OnPythonCopy();
    afx_msg void OnPythonPaste();
    afx_msg void OnPythonCut();

    afx_msg void OnPythonLoad();
    afx_msg void OnPythonSave();

    afx_msg void OnPythonRun();
    afx_msg void OnPythonStop();

    // Shader toolbar command message handlers
    afx_msg void OnShaderSetCode();

    // Called when the selected tab changes
    LRESULT OnTabChange(WPARAM wparam, LPARAM lparam);

    DECLARE_MESSAGE_MAP()
};

